//
//  String-Extension.swift
//  MyTouTiao
//
//  Created by Yuri on 2018/3/21.
//  Copyright © 2018年 Yuri. All rights reserved.
//

import Foundation

extension String {
    
    //去掉html文本中的<p>等标签
    var html2AttributeString : NSAttributedString? {
        do {
            return try NSAttributedString(data: data(using: String.Encoding.utf8)!, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding : String.Encoding.utf8.rawValue], documentAttributes: nil)
        } catch {
            print(error)
            return nil
        }
    }
    
    var html2String : String? {
        return html2AttributeString?.string ?? ""
    }
    
}
